import $ from "jquery";

const audio = new Audio("audio/bgm.mp3");
audio.loop = true;
audio.volume = 0.7;

let loaded = false;
function loadedCheck() {
    if (loaded) return;
    loaded = true;
    audio.play();
}

$(document).on("visibilitychange", () => {
    if (document.visibilityState === "visible") {
        audio.play();
    } else {
        audio.pause();
    }
}).on("focus", loadedCheck).on("click", loadedCheck).on("keydown", loadedCheck);

export { audio }